﻿/*
 * KLF Headless Browser
 * Written by Kris Oye <kristianoye@gmail.com>
 * Copyright (C) 2011-2012.  All rights reserved.
 */
namespace KLF.Lib.Browser.DOM
{
    #region Using Statements

    using System;

    #endregion

    /// <summary>
    /// The DOMImplementation interface provides a number of methods for 
    /// performing operations that are independent of any particular instance
    /// of the document object model. 
    /// </summary>
    public class DOMImplementation
    {
        #region DOM Level 1 Compliance

        /// <summary>
        /// Test if the DOM implementation implements a specific feature. 
        /// </summary>
        /// <param name="feature">The package name of the feature to test. In Level 1, the legal values are "HTML" and "XML" (case-insensitive).</param>
        /// <param name="version">This is the version number of the package name to test. In Level 1, this is the string "1.0". If the version is not specified, supporting any version of the feature will cause the method to return true.</param>
        /// <returns>true if the feature is implemented in the specified version, false otherwise.</returns>
        public virtual bool hasFeature(string feature, string version)
        {
            switch (feature.ToLower())
            {
                case "core":
                    return true;

                case "events":
                    return version.Equals("2.0");

                case "html":
                case "xml":
                    return version.Equals("1.0") || version.Equals("2.0");
            }
            return false;
        }

        #endregion

        #region DOM Level 2 Compliance

        /// <summary>
        /// 
        /// </summary>
        /// <param name="qualifiedName"></param>
        /// <param name="publicId"></param>
        /// <param name="systemId"></param>
        /// <returns></returns>
        public virtual DocumentType createDocumentType(string qualifiedName, string publicId, string systemId)
        {
            return DocumentType.Create(qualifiedName, publicId, systemId);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="qualifiedName"></param>
        /// <param name="publicId"></param>
        /// <param name="systemId"></param>
        /// <returns></returns>
        public virtual Document createDocument(string qualifiedName, string publicId, string systemId)
        {
            return DocumentType.Create(qualifiedName, publicId, systemId).CreateDocument();
        }

        #endregion

        #region DOM Level 3 Compliance

        /// <summary>
        /// This method returns a specialized object which implements the 
        /// specialized APIs of the specified feature and version, as specified
        /// in DOM Features. The specialized object may also be obtained by
        /// using binding-specific casting methods but is not necessarily 
        /// expected to, as discussed in Mixed DOM Implementations. This method
        /// also allow the implementation to provide specialized objects which
        /// do not support the DOMImplementation interface. 
        /// </summary>
        /// 
        /// <param name="feature">The name of the feature requested. Note that
        /// any plus sign "+" prepended to the name of the feature will be 
        /// ignored since it is not significant in the context of this method.</param>
        /// 
        /// <param name="version">This is the version number of the feature to test.</param>
        /// 
        /// <returns>Returns an object which implements the specialized APIs 
        /// of the specified feature and version, if any, or null if there is
        /// no object which implements interfaces associated with that feature.
        /// If the DOMObject returned by this method implements the 
        /// DOMImplementation interface, it must delegate to the primary core 
        /// DOMImplementation and not return results inconsistent with the 
        /// primary core DOMImplementation such as hasFeature, getFeature, 
        /// etc. </returns>
        public virtual object getFeature(string feature, string version)
        {
            return new NotImplementedException();
        }

        #endregion
    }
}
